#!/usr/bin/perl -w  
package clreqd_modules;

use strict;
use clreqdxml;
use clutils qw(to_bool);

#########################################################################
# This is a simple routine - it loads in the clreqd.xml file and	#
# sets the requests_ws element if not set and then writes out the	#
# contents if necessary.						#
#########################################################################

sub check_ws_clreqd_file {
my %ARGS=@_;
my $clear=0;

	if(exists($ARGS{CLEAR}) && defined($ARGS{CLEAR})) {
		$clear=to_bool($ARGS{CLEAR});
	}
	my $clreqd=new clreqdxml("$::ENV{TRUECL_CFG}/clreqd.xml");
	if(!defined($clreqd)) {
		return "ERROR Could not open the clreqd.xml file.";
	}
	
	my $has_requests_ws=$clreqd->get_requests_ws_value();
	if($clear==0 && defined($has_requests_ws)) {
		return "OK";
	}

	# Add the entry, since it is not currently present.		#

	if($clear==0 && ! -f "$::ENV{TRUECL_CFG}/clreqd_cmds_ws.xml") {
		return "ERROR Unable to find the file '$::ENV{TRUECL_CFG}/clreqd_cmds_ws.xml'.";
	}
	if($clear==0) {
		$clreqd->set_requests_ws_value("$::ENV{TRUECL_CFG}/clreqd_cmds_ws.xml");
	} else {
		$clreqd->remove_requests_ws_value("$::ENV{TRUECL_CFG}/clreqd_cmds_ws.xml");
	}

	#################################################################
	# Now write out the file contents...				#
	#################################################################

	my ($rc,$msg)=$clreqd->write_config("$::ENV{TRUECL_CFG}/clreqd.xml");
	if($rc==0) {
		return "ERROR $msg";
	}
	return "OK";
}

1;
